//
//  ACEQuestionAnswerController.m
//  ACE
//
//  Created by zhangtao on 2018/8/13.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "ACEQuestionAnswerController.h"
#import "ACEQuestionAnswerTableSectionHeaderView.h"
#import "ACEQuestionAnswerHeaderView.h"
#import "ACEQuestionsSubjectCell.h"
#import "ACEQuestionAnswerBottomView.h"
@interface ACEQuestionAnswerController ()<UITableViewDelegate,UITableViewDataSource,QuestionAsnwerBottomDelegate>
#define sectionViewHeight 40
#define bottomHeight tabBarHeight+20
@end

@implementation ACEQuestionAnswerController
{
    UITableView *table;
    ACEQuestionAnswerTableSectionHeaderView *sectionHeadView;
    ACEQuestionAnswerHeaderView *headView;
    ACEQuestionAnswerBottomView *bottomView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ACEWidth, self.view.bounds.size.height-navHeight-bottomHeight) style:UITableViewStyleGrouped];
    table.backgroundColor = [UIColor whiteColor];
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];
    table.sectionHeaderHeight = sectionViewHeight;
    table.tableHeaderView = self.sectionHeadView;
    [table registerNib:[UINib nibWithNibName:@"ACEQuestionsSubjectCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:self.bottomView];
}

-(ACEQuestionAnswerTableSectionHeaderView *)sectionHeadView{
    if (!sectionHeadView) {
        sectionHeadView = [[ACEQuestionAnswerTableSectionHeaderView alloc]initWithFrame:CGRectMake(0, 0, ACEWidth, sectionViewHeight) andTotalNum:10];
        sectionHeadView.second = @"01";
    }
    
    return sectionHeadView;
    
}

-(ACEQuestionAnswerHeaderView *)headView{
    if (!headView) {
        headView = [[ACEQuestionAnswerHeaderView alloc]initWithFrame:CGRectMake(0, 0, ACEWidth, 1)];
    }
    return headView;
}

-(ACEQuestionAnswerBottomView *)bottomView{
    if (!bottomView) {
        bottomView = [[ACEQuestionAnswerBottomView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(table.frame), ACEWidth, bottomHeight)];
        bottomView.delegate = self;
    }
    return bottomView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NSString *str = @"卡洛斯打给你了亲火";
    CGSize size = [ACEPublicTool textViewTextFont:[UIFont systemFontOfSize:17] andText:str Weight:ACEWidth-80.00 andHeight:1000.00];
    return size.height+20;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSString *str = @"卡洛斯打给你了亲火";
    CGSize size = [ACEPublicTool textViewTextFont:[UIFont systemFontOfSize:17] andText:str Weight:ACEWidth-80.00 andHeight:1000.00];
    CGFloat height = size.height+20;
    self.headView.height = height;
    self.headView.answer =  str;
    return self.headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 80;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ACEWidth, 80)];
    view.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(ACEWidth/2-80, view.center.y-25, 160, 60)];
    [btn setBackgroundColor:RGB(251, 176, 68, 1)];
    [btn setTitle:@"联系官方" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 30;
    [view addSubview:btn];
    return view;
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ACEQuestionsSubjectCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.subjectLab.text = @"A 答案一";
    return cell;
}


#pragma mark ----QuestionAsnwerBottomDelegate  底部按钮----
-(void)answerBottom:(ANSWER_CLICK)type{
    if (type == answer_left) {
        NSLog(@"上一题");
    }else if(type == anser_right){
        NSLog(@"下一题");
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
